package com.crrc.yzt.demo.activity

import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.crrc.yzt.demo.blue.R
import com.crrc.yzt.demo.fragment.CodeLoginFragment
import com.crrc.yzt.demo.fragment.PasswordLoginFragment
import com.google.android.material.tabs.TabLayoutMediator
import com.crrc.yzt.demo.base.BaseActivity
import com.crrc.yzt.demo.blue.databinding.ActivityLoginBinding
import java.util.Locale

class LoginActivity : BaseActivity() {


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStatusBarBackground(R.color.colorPrimary)
        val binding = ActivityLoginBinding.inflate(layoutInflater)

        setContentView(binding.root)

        binding.apply {

            Log.i("aaa", "onCreate: Locale.KOREA.country = ${Locale.KOREA.language} Locale.getDefault().country = ${Locale.getDefault().language}")

            if(Locale.KOREA.language == Locale.getDefault().language){
                val matrix = ColorMatrix()
                matrix.setSaturation(0F)

                val colorFilter =  ColorMatrixColorFilter(matrix);
                img.colorFilter = colorFilter;
            }

            viewPager.adapter = WeekPagerAdapter(supportFragmentManager,lifecycle)

            val titles = listOf(resources.getString(R.string.item_1),resources.getString(R.string.item_2))

            TabLayoutMediator(tabLayout, viewPager) { tab, position ->
                tab.text = titles[position]
            }.attach()


        }

    }

}


private class WeekPagerAdapter(
    fragmentManager: FragmentManager,
    lifecycle: Lifecycle
) : FragmentStateAdapter(fragmentManager, lifecycle) {

    private val weekList = mutableListOf<Fragment>()

    init {
        weekList.add(PasswordLoginFragment())
        weekList.add(CodeLoginFragment())
    }




    override fun getItemCount(): Int {
        return weekList.size
    }

    override fun createFragment(position: Int): Fragment {
        return weekList[position]
    }

}